package com.smart.mobile.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import com.smart.model.mobile.AddressInfo;
import com.smart.util.DBUtil;

public class AddressInfoDAO {
  /*
   * 获取当前用户的地址信息*
  **/
	public java.util.List<AddressInfo> getAddressInfo(int userid) throws Exception{
		AddressInfo addressinfo;
		java.util.List<AddressInfo> list = new ArrayList<AddressInfo>();
		String sql = "select * from address where userID = ?";
		Connection conn=DBUtil.getConnection();
	    PreparedStatement pSt = conn.prepareCall(sql);
	    pSt.setInt(1,userid);
	    ResultSet rs=pSt.executeQuery();
	    
	    while(rs.next()){
	    	addressinfo = new AddressInfo();
	    	addressinfo.setId(rs.getInt("Id"));
	    	addressinfo.setUserid(rs.getInt("userid"));
	    	addressinfo.setName(rs.getString("name"));
	    	addressinfo.setPhonenumber(rs.getString("phonenumber"));
	    	addressinfo.setBuilding(rs.getString("building"));
	    	addressinfo.setHousenumber(rs.getString("housenumber"));
	    	
	    	list.add(addressinfo);
	    }
		return list;
		
	}

}
